package io.red;

import java.util.concurrent.Semaphore;

/**
 *
 * @author Mariano Zapata
 */
public class Buffer<E> {
    
    private E buffer;
    private Semaphore semaforo;
    
    public Buffer()
    {
        semaforo= new Semaphore(0, true);
        buffer= null;
    }
    
    public void escribir(E o)
    {
        buffer= o;
        semaforo.release();
    }
    
    public E leer() throws InterruptedException
    {
        semaforo.acquire();
        return buffer;
    }
}
